<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html><head>


<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
 <title>
 zlib 1.2.5 Manual
 </title>
</head><body>
<h1> <em>zlib</em> 1.2.5 Manual </h1>
<hr>
<a name="Contents"></a><h2>Contents</h2>
<ol type="I">
<li> <a href="http://www.zlib.net/manual.html#Prologue">Prologue</a>
</li><li> <a href="http://www.zlib.net/manual.html#Version">Version</a>
</li><li> <a href="http://www.zlib.net/manual.html#Introduction">Introduction</a>
</li><li> <a href="http://www.zlib.net/manual.html#Stream">Stream Data 
Structures</a>
</li><li> <a href="http://www.zlib.net/manual.html#Usage">Structures 
Usage</a>
</li><li> <a href="http://www.zlib.net/manual.html#Constants">Constants</a>
</li><li> <a href="http://www.zlib.net/manual.html#Basic">Basic 
Functions</a>
</li><li> <a href="http://www.zlib.net/manual.html#Advanced">Advanced 
Functions</a>
</li><li> <a href="http://www.zlib.net/manual.html#Utility">Utility 
Functions</a>
</li><li> <a href="http://www.zlib.net/manual.html#Gzip">gzip File 
Access Functions</a>
</li><li> <a href="http://www.zlib.net/manual.html#Checksum">Checksum 
Functions</a>
</li><li> <a href="http://www.zlib.net/manual.html#Undocumented">Undocumented
 Functions</a>
</li></ol>
<hr>
<a name="Prologue"></a><h2> Prologue </h2>
<em>zlib</em> general purpose compression library<br>
  version 1.2.5, April 19th, 2010
<p>
  Copyright (C) 1995-2010 Jean-loup Gailly and Mark Adler
</p><p>
  This software is provided 'as-is', without any express or implied
  warranty.  In no event will the authors be held liable for any damages
  arising from the use of this software.
</p><p>
  Permission is granted to anyone to use this software for any purpose,
  including commercial applications, and to alter it and redistribute it
  freely, subject to the following restrictions:
</p><ol>
  <li> The origin of this software must not be misrepresented; you must 
not
     claim that you wrote the original software. If you use this 
software
     in a product, an acknowledgment in the product documentation would 
be
     appreciated but is not required.
  </li><li> Altered source versions must be plainly marked as such, and 
must not be
     misrepresented as being the original software.
  </li><li> This notice may not be removed or altered from any source 
distribution.
</li></ol>
Jean-loup Gailly&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Mark Adler<p>
  The data format used by the <em>zlib</em> library is described by RFCs
 (Request for
  Comments) 1950 to 1952 in the files
  <a href="http://www.ietf.org/rfc/rfc1950.txt">rfc1950.txt</a> (zlib 
format), 
  <a href="http://www.ietf.org/rfc/rfc1951.txt">rfc1951.txt</a> (deflate
 format) and 
  <a href="http://www.ietf.org/rfc/rfc1952.txt">rfc1952.txt</a> (gzip 
format).
<a name="Version"></a></p><h2> Version </h2>
<pre><b>#define ZLIB_VERSION "1.2.5"
#define ZLIB_VERNUM 0x1250
</b></pre>
<a name="Introduction"></a><h2> Introduction </h2>
     The <em>zlib</em> compression library provides in-memory 
compression and
  decompression functions, including integrity checks of the 
uncompressed
  data.  This version of the library supports only one compression 
method
  (deflation) but other algorithms will be added later and will have the
 same
  stream interface.
<p>
     Compression can be done in a single step if the buffers are large
  enough (for example if an input file is mmap'ed), or can be done by
  repeated calls of the compression function.  In the latter case, the
  application must provide more input and/or consume the output
  (providing more output space) before each call.
</p><p>
     The compressed data format used by default by the in-memory 
functions is
  the <em>zlib</em> format, which is a <em>zlib</em> wrapper documented 
in RFC 1950, wrapped
  around a deflate stream, which is itself documented in RFC 1951.
</p><p>
     The library also supports reading and writing files in <em>gzip</em>
 (.gz) format
  with an interface similar to that of stdio using the functions that 
start
  with "gz".  The <em>gzip</em> format is different from the <em>zlib</em>
 format.  <em>gzip</em> is a
  <em>gzip</em> wrapper, documented in RFC 1952, wrapped around a 
deflate stream.
</p><p>
     This library can optionally read and write <em>gzip</em> streams in
 memory as well.
</p><p>
     The <em>zlib</em> format was designed to be compact and fast for 
use in memory
  and on communications channels.  The <em>gzip</em> format was designed
 for single-
  file compression on file systems, has a larger header than <em>zlib</em>
 to maintain
  directory information, and uses a different, slower check method than <em>zlib</em>.
</p><p>
     The library does not install any signal handler. The decoder checks
  the consistency of the compressed data, so the library should never
  crash even in case of corrupted input.
<a name="Stream"></a></p><h2> Stream Data Structures </h2>
<pre><b>typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
typedef void   (*free_func)  OF((voidpf opaque, voidpf address));

struct internal_state;

typedef struct z_stream_s {
    Bytef    *next_in;  /* next input byte */
    uInt     avail_in;  /* number of bytes available at next_in */
    uLong    total_in;  /* total nb of input bytes read so far */

    Bytef    *next_out; /* next output byte should be put there */
    uInt     avail_out; /* remaining free space at next_out */
    uLong    total_out; /* total nb of bytes output so far */

    char     *msg;      /* last error message, NULL if no error */
    struct internal_state FAR *state; /* not visible by applications */

    alloc_func zalloc;  /* used to allocate the internal state */
    free_func  zfree;   /* used to free the internal state */
    voidpf     opaque;  /* private data object passed to zalloc and zfree */

    int     data_type;  /* best guess about the data type: binary or text */
    uLong   adler;      /* adler32 value of the uncompressed data */
    uLong   reserved;   /* reserved for future use */
} z_stream;

typedef z_stream FAR *z_streamp;

</b></pre>
     <em>gzip</em> header information passed to and from <em>zlib</em> 
routines.  See RFC 1952
  for more details on the meanings of these fields.
<pre><b>
typedef struct gz_header_s {
    int     text;       /* true if compressed data believed to be text */
    uLong   time;       /* modification time */
    int     xflags;     /* extra flags (not used when writing a gzip file) */
    int     os;         /* operating system */
    Bytef   *extra;     /* pointer to extra field or Z_NULL if none */
    uInt    extra_len;  /* extra field length (valid if extra != Z_NULL) */
    uInt    extra_max;  /* space at extra (only when reading header) */
    Bytef   *name;      /* pointer to zero-terminated file name or Z_NULL */
    uInt    name_max;   /* space at name (only when reading header) */
    Bytef   *comment;   /* pointer to zero-terminated comment or Z_NULL */
    uInt    comm_max;   /* space at comment (only when reading header) */
    int     hcrc;       /* true if there was or will be a header crc */
    int     done;       /* true when done reading gzip header (not used
                           when writing a gzip file) */
} gz_header;

typedef gz_header FAR *gz_headerp;
</b></pre>
<a name="Usage"></a><h2> Structures Usage </h2>
   The application must update <tt>next_in</tt> and <tt>avail_in</tt> 
when <tt>avail_in</tt> has
   dropped to zero. It must update <tt>next_out</tt> and <tt>avail_out</tt>
 when <tt>avail_out</tt>
   has dropped to zero. The application must initialize <tt>zalloc</tt>,
 <tt>zfree</tt> and
   <tt>opaque</tt> before calling the init function. All other fields 
are set by the
   compression library and must not be updated by the application.
<p>
   The <tt>opaque</tt> value provided by the application will be passed 
as the first
   parameter for calls of <tt>zalloc</tt> and <tt>zfree</tt>. This can 
be useful for custom
   memory management. The compression library attaches no meaning to the
   <tt>opaque</tt> value.
</p><p>
   <tt>zalloc</tt> must return <tt>Z_NULL</tt> if there is not enough 
memory for the object.
   If <em>zlib</em> is used in a multi-threaded application, <tt>zalloc</tt>
 and <tt>zfree</tt> must be
   thread safe.
</p><p>
   On 16-bit systems, the functions <tt>zalloc</tt> and <tt>zfree</tt> 
must be able to allocate
   exactly 65536 bytes, but will not be required to allocate more than 
this
   if the symbol <tt>MAXSEG_64K</tt> is defined (see zconf.h). WARNING: 
On MSDOS,
   pointers returned by <tt>zalloc</tt> for objects of exactly 65536 
bytes <em>must</em>
   have their offset normalized to zero. The default allocation function
   provided by this library ensures this (see zutil.c). To reduce memory
   requirements and avoid any allocation of 64K objects, at the expense 
of
   compression ratio, compile the library with <tt>-DMAX_WBITS=14</tt> 
(see zconf.h).
</p><p>
   The fields <tt>total_in</tt> and <tt>total_out</tt> can be used for 
statistics or
   progress reports. After compression, <tt>total_in</tt> holds the 
total size of
   the uncompressed data and may be saved for use in the decompressor
   (particularly if the decompressor wants to decompress everything in
   a single step).
<a name="Constants"></a></p><h2> Constants </h2>
Allowed <tt>flush</tt> values; see <tt>deflate()</tt> and <tt>inflate()</tt>
 below for details.
<pre><b>#define Z_NO_FLUSH      0
#define Z_PARTIAL_FLUSH 1
#define Z_SYNC_FLUSH    2
#define Z_FULL_FLUSH    3
#define Z_FINISH        4
#define Z_BLOCK         5
#define Z_TREES         6
</b></pre>
Return codes for the compression/decompression functions. Negative
values are errors, positive values are used for special but normal 
events.
<pre><b>#define Z_OK            0
#define Z_STREAM_END    1
#define Z_NEED_DICT     2
#define Z_ERRNO        (-1)
#define Z_STREAM_ERROR (-2)
#define Z_DATA_ERROR   (-3)
#define Z_MEM_ERROR    (-4)
#define Z_BUF_ERROR    (-5)
#define Z_VERSION_ERROR (-6)
</b></pre>
Compression levels.
<pre><b>#define Z_NO_COMPRESSION         0
#define Z_BEST_SPEED             1
#define Z_BEST_COMPRESSION       9
#define Z_DEFAULT_COMPRESSION  (-1)
</b></pre>
Compression strategy &#8212; see <tt>deflateInit2()</tt> below for details.
<pre><b>#define Z_FILTERED            1
#define Z_HUFFMAN_ONLY        2
#define Z_RLE                 3
#define Z_FIXED               4
#define Z_DEFAULT_STRATEGY    0
</b></pre>
Possible values of the <tt>data_type</tt> field (though see <tt>inflate()</tt>).
<pre><b>#define Z_BINARY   0
#define Z_TEXT     1
#define Z_ASCII    Z_TEXT   /* for compatibility with 1.2.2 and earlier */
#define Z_UNKNOWN  2
</b></pre>
The deflate compression method (the only one supported in this version).
<pre><b>#define Z_DEFLATED   8
</b></pre>
For initializing <tt>zalloc</tt>, <tt>zfree</tt>, <tt>opaque</tt>.
<pre><b>#define Z_NULL  0
</b></pre>
For compatibility with versions &lt; 1.0.2.
<pre><b>#define zlib_version zlibVersion()
</b></pre>
<a name="Basic"></a><h2> Basic Functions </h2>
<pre><b>ZEXTERN const char * ZEXPORT zlibVersion OF((void));
</b></pre>
   The application can compare <tt>zlibVersion</tt> and <tt>ZLIB_VERSION</tt>
 for consistency.
   If the first character differs, the library code actually used is
   not compatible with the zlib.h header file used by the application.
   This check is automatically made by <tt>deflateInit</tt> and <tt>inflateInit</tt>.
<pre><b>
ZEXTERN int ZEXPORT deflateInit OF((z_streamp strm, int level));
</b></pre>
     Initializes the internal stream state for compression. The fields
   <tt>zalloc</tt>, <tt>zfree</tt> and <tt>opaque</tt> must be 
initialized before by the caller.
   If <tt>zalloc</tt> and <tt>zfree</tt> are set to <tt>Z_NULL</tt>, <tt>deflateInit</tt>
 updates them to
   use default allocation functions.
<p>
     The compression level must be <tt>Z_DEFAULT_COMPRESSION</tt>, or 
between 0 and 9:
   1 gives best speed, 9 gives best compression, 0 gives no compression 
at
   all (the input data is simply copied a block at a time).
   <tt>Z_DEFAULT_COMPRESSION</tt> requests a default compromise between 
speed and
   compression (currently equivalent to level 6).
</p><p>
     <tt>deflateInit</tt> returns <tt>Z_OK</tt> if success, <tt>Z_MEM_ERROR</tt>
 if there was not
   enough memory, <tt>Z_STREAM_ERROR</tt> if <tt>level</tt> is not a 
valid compression level,
   <tt>Z_VERSION_ERROR</tt> if the <em>zlib</em> library version (<tt>zlib_version</tt>)
 is incompatible
   with the version assumed by the caller (<tt>ZLIB_VERSION</tt>).
   <tt>msg</tt> is set to null if there is no error message.  <tt>deflateInit</tt>
 does not
   perform any compression: this will be done by deflate().
</p><pre><b>
ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
</b></pre>
    <tt>deflate</tt> compresses as much data as possible, and stops when
 the input
  buffer becomes empty or the output buffer becomes full. It may 
introduce some
  output latency (reading input without producing any output) except 
when
  forced to flush.
<p>
    The detailed semantics are as follows. <tt>deflate</tt> performs one
 or both of the
  following actions:
</p><p>
</p><ul>
<li>Compress more input starting at <tt>next_in</tt> and update <tt>next_in</tt>
 and <tt>avail_in</tt>
    accordingly. If not all input can be processed (because there is not
    enough room in the output buffer), <tt>next_in</tt> and <tt>avail_in</tt>
 are updated and
    processing will resume at this point for the next call of <tt>deflate()</tt>.
</li><li>Provide more output starting at <tt>next_out</tt> and update <tt>next_out</tt>
 and <tt>avail_out</tt>
    accordingly. This action is forced if the parameter <tt>flush</tt> 
is non zero.
    Forcing flush frequently degrades the compression ratio, so this 
parameter
    should be set only when necessary (in interactive applications).
    Some output may be provided even if <tt>flush</tt> is not set.
</li></ul>
  Before the call of <tt>deflate()</tt>, the application should ensure 
that at least
  one of the actions is possible, by providing more input and/or 
consuming
  more output, and updating <tt>avail_in</tt> or <tt>avail_out</tt> 
accordingly; <tt>avail_out</tt>
  should never be zero before the call. The application can consume the
  compressed output when it wants, for example when the output buffer is
 full
  (<tt>avail_out == 0</tt>), or after each call of <tt>deflate()</tt>. 
If <tt>deflate</tt> returns <tt>Z_OK</tt>
  and with zero <tt>avail_out</tt>, it must be called again after making
 room in the
  output buffer because there might be more output pending.
<p>
    Normally the parameter <tt>flush</tt> is set to <tt>Z_NO_FLUSH</tt>,
 which allows <tt>deflate</tt> to
  decide how much data to accumulate before producing output, in order 
to
  maximize compression.
</p><p>
    If the parameter <tt>flush</tt> is set to <tt>Z_SYNC_FLUSH</tt>, all
 pending output is
  flushed to the output buffer and the output is aligned on a byte 
boundary, so
  that the decompressor can get all input data available so far. (In 
particular
  <tt>avail_in</tt> is zero after the call if enough output space has 
been provided
  before the call.)  Flushing may degrade compression for some 
compression
  algorithms and so it should be used only when necessary.  This
  completes the current deflate block and follows it with an empty 
stored block
  that is three bits plus filler bits to the next byte, followed by four
 bytes
  (00 00 ff ff).
</p><p>
    If <tt>flush</tt> is set to <tt>Z_PARTIAL_FLUSH</tt>, all pending 
output is flushed to the
  output buffer, but the output is not aligned to a byte boundary.  All 
of the
  input data so far will be available to the decompressor, as for <tt>Z_SYNC_FLUSH</tt>.
  This completes the current deflate block and follows it with an empty 
fixed
  codes block that is 10 bits long.  This assures that enough bytes are 
output
  in order for the decompressor to finish the block before the empty 
fixed code
  block.
</p><p>
    If flush is set to <tt>Z_BLOCK</tt>, a deflate block is completed 
and emitted, as
  for <tt>Z_SYNC_FLUSH</tt>, but the output is not aligned on a byte 
boundary, and up to
  seven bits of the current block are held to be written as the next 
byte after
  the next deflate block is completed.  In this case, the decompressor 
may not
  be provided enough bits at this point in order to complete 
decompression of
  the data provided so far to the compressor.  It may need to wait for 
the next
  block to be emitted.  This is for advanced applications that need to 
control
  the emission of deflate blocks.
</p><p>
    If <tt>flush</tt> is set to <tt>Z_FULL_FLUSH</tt>, all output is 
flushed as with
  <tt>Z_SYNC_FLUSH</tt>, and the compression state is reset so that 
decompression can
  restart from this point if previous compressed data has been damaged 
or if
  random access is desired. Using <tt>Z_FULL_FLUSH</tt> too often can 
seriously degrade
  compression.
</p><p>
    If <tt>deflate</tt> returns with <tt>avail_out == 0</tt>, this 
function must be called again
  with the same value of the <tt>flush</tt> parameter and more output 
space (updated
  <tt>avail_out</tt>), until the flush is complete (<tt>deflate</tt> 
returns with non-zero
  <tt>avail_out</tt>). In the case of a <tt>Z_FULL_FLUSH</tt> or <tt>Z_SYNC_FLUSH</tt>,
 make sure that
  <tt>avail_out</tt> is greater than six to avoid repeated flush markers
 due to
  <tt>avail_out == 0</tt> on return.
</p><p>
    If the parameter <tt>flush</tt> is set to <tt>Z_FINISH</tt>, pending
 input is processed,
  pending output is flushed and <tt>deflate</tt> returns with <tt>Z_STREAM_END</tt>
 if there
  was enough output space; if <tt>deflate</tt> returns with <tt>Z_OK</tt>,
 this function must be
  called again with <tt>Z_FINISH</tt> and more output space (updated <tt>avail_out</tt>)
 but no
  more input data, until it returns with <tt>Z_STREAM_END</tt> or an 
error. After
  <tt>deflate</tt> has returned <tt>Z_STREAM_END</tt>, the only possible
 operations on the
  stream are <tt>deflateReset</tt> or <tt>deflateEnd</tt>.
</p><p>
    <tt>Z_FINISH</tt> can be used immediately after <tt>deflateInit</tt>
 if all the compression
  is to be done in a single step. In this case, <tt>avail_out</tt> must 
be at least
  the value returned by <tt>deflateBound</tt> (see below). If <tt>deflate</tt>
 does not return
  <tt>Z_STREAM_END</tt>, then it must be called again as described 
above.
</p><p>
    <tt>deflate()</tt> sets <tt>strm-&gt;adler</tt> to the adler32 
checksum of all input read
  so far (that is, <tt>total_in</tt> bytes).
</p><p>
    <tt>deflate()</tt> may update <tt>strm-&gt;data_type</tt> if it can 
make a good guess about
  the input data type (<tt>Z_BINARY</tt> or <tt>Z_TEXT</tt>). In doubt, 
the data is considered
  binary. This field is only for information purposes and does not 
affect
  the compression algorithm in any manner.
</p><p>
    <tt>deflate()</tt> returns <tt>Z_OK</tt> if some progress has been 
made (more input
  processed or more output produced), <tt>Z_STREAM_END</tt> if all input
 has been
  consumed and all output has been produced (only when <tt>flush</tt> is
 set to
  <tt>Z_FINISH</tt>), <tt>Z_STREAM_ERROR</tt> if the stream state was 
inconsistent (for example
  if <tt>next_in</tt> or <tt>next_out</tt> was <tt>NULL</tt>), <tt>Z_BUF_ERROR</tt>
 if no progress is possible
  (for example <tt>avail_in</tt> or <tt>avail_out</tt> was zero). Note 
that <tt>Z_BUF_ERROR</tt> is not
  fatal, and <tt>deflate()</tt> can be called again with more input and 
more output
  space to continue compressing.
</p><pre><b>
ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
</b></pre>
     All dynamically allocated data structures for this stream are 
freed.
   This function discards any unprocessed input and does not flush any
   pending output.
<p>
     <tt>deflateEnd</tt> returns <tt>Z_OK</tt> if success, <tt>Z_STREAM_ERROR</tt>
 if the
   stream state was inconsistent, <tt>Z_DATA_ERROR</tt> if the stream 
was freed
   prematurely (some input or output was discarded). In the error case,
   <tt>msg</tt> may be set but then points to a static string (which 
must not be
   deallocated).
</p><pre><b>
ZEXTERN int ZEXPORT inflateInit OF((z_streamp strm));
</b></pre>
     Initializes the internal stream state for decompression. The fields
   <tt>next_in</tt>, <tt>avail_in</tt>, <tt>zalloc</tt>, <tt>zfree</tt> 
and <tt>opaque</tt> must be initialized before by
   the caller. If <tt>next_in</tt> is not <tt>Z_NULL</tt> and <tt>avail_in</tt>
 is large enough (the exact
   value depends on the compression method), <tt>inflateInit</tt> 
determines the
   compression method from the <em>zlib</em> header and allocates all 
data structures
   accordingly; otherwise the allocation will be deferred to the first 
call of
   <tt>inflate</tt>.  If <tt>zalloc</tt> and <tt>zfree</tt> are set to <tt>Z_NULL</tt>,
 <tt>inflateInit</tt> updates them to
   use default allocation functions.
<p>
     <tt>inflateInit</tt> returns <tt>Z_OK</tt> if success, <tt>Z_MEM_ERROR</tt>
 if there was not enough
   memory, <tt>Z_VERSION_ERROR</tt> if the zlib library version is 
incompatible with the
   version assumed by the caller, or <tt>Z_STREAM_ERROR</tt> if the 
parameters are
   invalid, such as a null pointer to the structure.  <tt>msg</tt> is 
set to null if
   there is no error message.  <tt>inflateInit</tt> does not perform any
 decompression
   apart from possibly reading the <em>zlib</em> header if present: 
actual decompression
   will be done by <tt>inflate()</tt>.  (So <tt>next_in</tt> and <tt>avail_in</tt>
 may be modified, but
   <tt>next_out</tt> and <tt>avail_out</tt> are unused and unchanged.) 
The current implementation
   of <tt>inflateInit()</tt> does not process any header information -- 
that is deferred
   until <tt>inflate()</tt> is called.
</p><pre><b>
ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
</b></pre>
    <tt>inflate</tt> decompresses as much data as possible, and stops 
when the input
  buffer becomes empty or the output buffer becomes full. It may 
introduce
  some output latency (reading input without producing any output) 
except when
  forced to flush.
<p>
  The detailed semantics are as follows. <tt>inflate</tt> performs one 
or both of the
  following actions:
</p><ul>
<li>Decompress more input starting at <tt>next_in</tt> and update <tt>next_in</tt>
 and <tt>avail_in</tt>
    accordingly. If not all input can be processed (because there is not
    enough room in the output buffer), <tt>next_in</tt> is updated and 
processing
    will resume at this point for the next call of <tt>inflate()</tt>.
</li><li>Provide more output starting at <tt>next_out</tt> and update <tt>next_out</tt>
 and <tt>avail_out</tt>
    accordingly.  <tt>inflate()</tt> provides as much output as 
possible, until there
    is no more input data or no more space in the output buffer (see 
below
    about the <tt>flush</tt> parameter).
</li></ul>
  Before the call of <tt>inflate()</tt>, the application should ensure 
that at least
  one of the actions is possible, by providing more input and/or 
consuming
  more output, and updating the <tt>next_</tt>* and <tt>avail_</tt>* 
values accordingly.
  The application can consume the uncompressed output when it wants, for
  example when the output buffer is full (<tt>avail_out == 0</tt>), or 
after each
  call of <tt>inflate()</tt>. If <tt>inflate</tt> returns <tt>Z_OK</tt> 
and with zero <tt>avail_out</tt>, it
  must be called again after making room in the output buffer because 
there
  might be more output pending.
<p>
    The <tt>flush</tt> parameter of <tt>inflate()</tt> can be <tt>Z_NO_FLUSH</tt>,
 <tt>Z_SYNC_FLUSH</tt>,
  <tt>Z_FINISH</tt>, <tt>Z_BLOCK</tt>, or <tt>Z_TREES</tt>. <tt>Z_SYNC_FLUSH</tt>
 requests that <tt>inflate()</tt> flush as much
  output as possible to the output buffer. <tt>Z_BLOCK</tt> requests 
that <tt>inflate()</tt> stop
  if and when it gets to the next deflate block boundary. When decoding 
the
  <em>zlib</em> or <em>gzip</em> format, this will cause <tt>inflate()</tt>
 to return immediately after
  the header and before the first block. When doing a raw inflate, <tt>inflate()</tt>
  will go ahead and process the first block, and will return when it 
gets to
  the end of that block, or when it runs out of data.
</p><p>
    The <tt>Z_BLOCK</tt> option assists in appending to or combining 
deflate streams.
  Also to assist in this, on return <tt>inflate()</tt> will set <tt>strm-&gt;data_type</tt>
 to the
  number of unused bits in the last byte taken from <tt>strm-&gt;next_in</tt>,
 plus 64
  if <tt>inflate()</tt> is currently decoding the last block in the 
deflate stream,
  plus 128 if <tt>inflate()</tt> returned immediately after decoding an 
end-of-block
  code or decoding the complete header up to just before the first byte 
of the
  deflate stream. The end-of-block will not be indicated until all of 
the
  uncompressed data from that block has been written to <tt>strm-&gt;next_out</tt>.
  The
  number of unused bits may in general be greater than seven, except 
when
  bit 7 of <tt>data_type</tt> is set, in which case the number of unused
 bits will be
  less than eight.  <tt>data_type</tt> is set as noted here every time <tt>inflate()</tt>
 returns for all
  flush options, and so can be used to determine the amount of currently
  consumed input in bits.
</p><p>
    The <tt>Z_TREES</tt> option behaves as <tt>Z_BLOCK</tt> does, but it
 also returns when the
  end of each deflate block header is reached, before any actual data in
 that
  block is decoded.  This allows the caller to determine the length of 
the
  deflate block header for later use in random access within a deflate 
block.
  256 is added to the value of <tt>strm-&gt;data_type</tt> when <tt>inflate()</tt>
 returns
  immediately after reaching the end of the deflate block header.
</p><p>
    <tt>inflate()</tt> should normally be called until it returns <tt>Z_STREAM_END</tt>
 or an
  error. However if all decompression is to be performed in a single 
step
  (a single call of <tt>inflate</tt>), the parameter <tt>flush</tt> 
should be set to
  <tt>Z_FINISH</tt>. In this case all pending input is processed and all
 pending
  output is flushed; <tt>avail_out</tt> must be large enough to hold all
 the
  uncompressed data. (The size of the uncompressed data may have been 
saved
  by the compressor for this purpose.) The next operation on this stream
 must
  be <tt>inflateEnd</tt> to deallocate the decompression state. The use 
of <tt>Z_FINISH</tt>
  is never required, but can be used to inform <tt>inflate</tt> that a 
faster approach
  may be used for the single <tt>inflate()</tt> call.
</p><p>
     In this implementation, <tt>inflate()</tt> always flushes as much 
output as
  possible to the output buffer, and always uses the faster approach on 
the
  first call. So the only effect of the <tt>flush</tt> parameter in this
 implementation
  is on the return value of <tt>inflate()</tt>, as noted below, or when 
it returns early
  because <tt>Z_BLOCK</tt> or <tt>Z_TREES</tt> is used.
</p><p>
     If a preset dictionary is needed after this call (see <tt>inflateSetDictionary</tt>
  below), <tt>inflate</tt> sets <tt>strm-&gt;adler</tt> to the adler32 
checksum of the dictionary
  chosen by the compressor and returns <tt>Z_NEED_DICT</tt>; otherwise 
it sets
  <tt>strm-&gt;adler</tt> to the adler32 checksum of all output produced
 so far (that is,
  <tt>total_out</tt> bytes) and returns <tt>Z_OK</tt>, <tt>Z_STREAM_END</tt>
 or an error code as described
  below. At the end of the stream, <tt>inflate()</tt> checks that its 
computed adler32
  checksum is equal to that saved by the compressor and returns <tt>Z_STREAM_END</tt>
  only if the checksum is correct.
</p><p>
    <tt>inflate()</tt> will decompress and check either <em>zlib</em>-wrapped
 or <em>gzip</em>-wrapped
  deflate data.  The header type is detected automatically, if requested
 when
  initializing with <tt>inflateInit2()</tt>.  Any information
  contained in the <em>gzip</em> header is not retained, so applications
 that need that
  information should instead use raw inflate, see <tt>inflateInit2()</tt>
 below, or
  <tt>inflateBack()</tt> and perform their own processing of the <em>gzip</em>
 header and
  trailer.
</p><p>
    <tt>inflate()</tt> returns <tt>Z_OK</tt> if some progress has been 
made (more input processed
  or more output produced), <tt>Z_STREAM_END</tt> if the end of the 
compressed data has
  been reached and all uncompressed output has been produced, <tt>Z_NEED_DICT</tt>
 if a
  preset dictionary is needed at this point, <tt>Z_DATA_ERROR</tt> if 
the input data was
  corrupted (input stream not conforming to the <em>zlib</em> format or 
incorrect check
  value), <tt>Z_STREAM_ERROR</tt> if the stream structure was 
inconsistent (for example
  if <tt>next_in</tt> or <tt>next_out</tt> was <tt>NULL</tt>), <tt>Z_MEM_ERROR</tt>
 if there was not enough memory,
  <tt>Z_BUF_ERROR</tt> if no progress is possible or if there was not 
enough room in the
  output buffer when <tt>Z_FINISH</tt> is used. Note that <tt>Z_BUF_ERROR</tt>
 is not fatal, and
  <tt>inflate()</tt> can be called again with more input and more output
 space to
  continue decompressing. If <tt>Z_DATA_ERROR</tt> is returned, the 
application may then
  call <tt>inflateSync()</tt> to look for a good compression block if a 
partial recovery
  of the data is desired.
</p><pre><b>
ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
</b></pre>
     All dynamically allocated data structures for this stream are 
freed.
   This function discards any unprocessed input and does not flush any
   pending output.
<p>
     <tt>inflateEnd</tt> returns <tt>Z_OK</tt> if success, <tt>Z_STREAM_ERROR</tt>
 if the stream state
   was inconsistent. In the error case, <tt>msg</tt> may be set but then
 points to a
   static string (which must not be deallocated).
<a name="Advanced"></a></p><h2> Advanced Functions </h2>
    The following functions are needed only in some special 
applications.
<pre><b>
ZEXTERN int ZEXPORT deflateInit2 OF((z_streamp strm,
                                     int  level,
                                     int  method,
                                     int  windowBits,
                                     int  memLevel,
                                     int  strategy));
</b></pre>
     This is another version of <tt>deflateInit</tt> with more 
compression options. The
   fields <tt>next_in</tt>, <tt>zalloc</tt>, <tt>zfree</tt> and <tt>opaque</tt>
 must be initialized before by
   the caller.
<p>
     The <tt>method</tt> parameter is the compression method. It must be
 <tt>Z_DEFLATED</tt> in
   this version of the library.
</p><p>
     The <tt>windowBits</tt> parameter is the base two logarithm of the 
window size
   (the size of the history buffer). It should be in the range 8..15 for
 this
   version of the library. Larger values of this parameter result in 
better
   compression at the expense of memory usage. The default value is 15 
if
   <tt>deflateInit</tt> is used instead.
</p><p>
     <tt>windowBits</tt> can also be &#8211;8..&#8211;15 for raw deflate. In this 
case, <tt>-windowBits</tt>
   determines the window size. <tt>deflate()</tt> will then generate raw
 deflate data
   with no <em>zlib</em> header or trailer, and will not compute an 
adler32 check value.
</p><p>
     <tt>windowBits</tt> can also be greater than 15 for optional <em>gzip</em>
 encoding. Add
   16 to <tt>windowBits</tt> to write a simple <em>gzip</em> header and 
trailer around the
   compressed data instead of a <em>zlib</em> wrapper. The <em>gzip</em>
 header will have no
   file name, no extra data, no comment, no modification time (set to 
zero),
   no header crc, and the operating system will be set to 255 (unknown).
  If a
   <em>gzip</em> stream is being written, <tt>strm-&gt;adler</tt> is a 
crc32 instead of an adler32.
</p><p>
     The <tt>memLevel</tt> parameter specifies how much memory should be
 allocated
   for the internal compression state. <tt>memLevel=1</tt> uses minimum 
memory but
   is slow and reduces compression ratio; <tt>memLevel=9</tt> uses 
maximum memory
   for optimal speed. The default value is 8. See zconf.h for total 
memory
   usage as a function of <tt>windowBits</tt> and <tt>memLevel</tt>.
</p><p>
     The <tt>strategy</tt> parameter is used to tune the compression 
algorithm. Use the
   value <tt>Z_DEFAULT_STRATEGY</tt> for normal data, <tt>Z_FILTERED</tt>
 for data produced by a
   filter (or predictor), <tt>Z_HUFFMAN_ONLY</tt> to force Huffman 
encoding only (no
   string match), or <tt>Z_RLE</tt> to limit match distances to one 
(run-length
   encoding). Filtered data consists mostly of small values with a 
somewhat
   random distribution. In this case, the compression algorithm is tuned
 to
   compress them better. The effect of <tt>Z_FILTERED</tt> is to force 
more Huffman
   coding and less string matching; it is somewhat intermediate between
   <tt>Z_DEFAULT_STRATEGY</tt> and <tt>Z_HUFFMAN_ONLY</tt>. <tt>Z_RLE</tt>
 is designed to be almost as fast as
   <tt>Z_HUFFMAN_ONLY</tt>, but give better compression for <em>PNG</em>
 image data. The <tt>strategy</tt>
   parameter only affects the compression ratio but not the correctness 
of the
   compressed output even if it is not set appropriately.  <tt>Z_FIXED</tt>
 prevents the
   use of dynamic Huffman codes, allowing for a simpler decoder for 
special
   applications.
</p><p>
      <tt>deflateInit2</tt> returns <tt>Z_OK</tt> if success, <tt>Z_MEM_ERROR</tt>
 if there was not enough
   memory, <tt>Z_STREAM_ERROR</tt> if a parameter is invalid (such as an
 invalid
   method), or <tt>Z_VERSION_ERROR</tt> if the <em>zlib</em> library 
version (<tt>zlib_version</tt>) is
   incompatible with the version assumed by the caller (<tt>ZLIB_VERSION</tt>).
 <tt>msg</tt> is set to null if there is no error message.  <tt>deflateInit2</tt>
 does
   not perform any compression: this will be done by <tt>deflate()</tt>.
</p><pre><b>
ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
                                             const Bytef *dictionary,
                                             uInt  dictLength));
</b></pre>
   Initializes the compression dictionary from the given byte sequence
   without producing any compressed output. This function must be called
   immediately after <tt>deflateInit</tt>, <tt>deflateInit2</tt> or <tt>deflateReset</tt>,
 before any
   call of <tt>deflate</tt>. The compressor and decompressor must use 
exactly the same
   dictionary (see <tt>inflateSetDictionary</tt>).
<p>
     The dictionary should consist of strings (byte sequences) that are 
likely
   to be encountered later in the data to be compressed, with the most 
commonly
   used strings preferably put towards the end of the dictionary. Using a
   dictionary is most useful when the data to be compressed is short and
 can be
   predicted with good accuracy; the data can then be compressed better 
than
   with the default empty dictionary.
</p><p>
     Depending on the size of the compression data structures selected 
by
   <tt>deflateInit</tt> or <tt>deflateInit2</tt>, a part of the 
dictionary may in effect be
   discarded, for example if the dictionary is larger than the window 
size in
   <tt>deflate</tt> or <tt>deflate2</tt>. Thus the strings most likely 
to be useful should be
   put at the end of the dictionary, not at the front. In addition, the
   current implementation of <tt>deflate</tt> will use at most the 
window size minus
   262 bytes of the provided dictionary.
</p><p>
     Upon return of this function, <tt>strm-&gt;adler</tt> is set to the
 adler32 value
   of the dictionary; the decompressor may later use this value to 
determine
   which dictionary has been used by the compressor. (The adler32 value
   applies to the whole dictionary even if only a subset of the 
dictionary is
   actually used by the compressor.) If a raw deflate was requested, 
then the
   adler32 value is not computed and <tt>strm-&gt;adler</tt> is not set.
</p><p>
     <tt>deflateSetDictionary</tt> returns <tt>Z_OK</tt> if success, or <tt>Z_STREAM_ERROR</tt>
 if a
   parameter is invalid (such as <tt>NULL</tt> dictionary) or the stream
 state is
   inconsistent (for example if <tt>deflate</tt> has already been called
 for this stream
   or if the compression method is bsort). <tt>deflateSetDictionary</tt>
 does not
   perform any compression: this will be done by <tt>deflate()</tt>.
</p><pre><b>
ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
                                    z_streamp source));
</b></pre>
   Sets the destination stream as a complete copy of the source stream.
<p>
     This function can be useful when several compression strategies 
will be
   tried, for example when there are several ways of pre-processing the 
input
   data with a filter. The streams that will be discarded should then be
 freed
   by calling <tt>deflateEnd</tt>.  Note that <tt>deflateCopy</tt> 
duplicates the internal
   compression state which can be quite large, so this strategy is slow 
and
   can consume lots of memory.
</p><p>
     <tt>deflateCopy</tt> returns <tt>Z_OK</tt> if success, <tt>Z_MEM_ERROR</tt>
 if there was not
   enough memory, <tt>Z_STREAM_ERROR</tt> if the source stream state was
 inconsistent
   (such as <tt>zalloc</tt> being <tt>NULL</tt>). <tt>msg</tt> is left 
unchanged in both source and
   destination.
</p><pre><b>
ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
</b></pre>
     This function is equivalent to <tt>deflateEnd</tt> followed by <tt>deflateInit</tt>,
   but does not free and reallocate all the internal compression state.
   The stream will keep the same compression level and any other 
attributes
   that may have been set by <tt>deflateInit2</tt>.
<p>
      <tt>deflateReset</tt> returns <tt>Z_OK</tt> if success, or <tt>Z_STREAM_ERROR</tt>
 if the source
   stream state was inconsistent (such as <tt>zalloc</tt> or state being
 <tt>NULL</tt>).
</p><pre><b>
ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
                                      int level,
                                      int strategy));
</b></pre>
     Dynamically update the compression level and compression strategy. 
 The
   interpretation of <tt>level</tt> and <tt>strategy</tt> is as in <tt>deflateInit2</tt>.
  This can be
   used to switch between compression and straight copy of the input 
data, or
   to switch to a different kind of input data requiring a different
   strategy. If the compression level is changed, the input available so
 far
   is compressed with the old level (and may be flushed); the new level 
will
   take effect only at the next call of <tt>deflate()</tt>.
<p>
     Before the call of <tt>deflateParams</tt>, the stream state must be
 set as for
   a call of <tt>deflate()</tt>, since the currently available input may
 have to
   be compressed and flushed. In particular, <tt>strm-&gt;avail_out</tt>
 must be non-zero.
</p><p>
     <tt>deflateParams</tt> returns <tt>Z_OK</tt> if success, <tt>Z_STREAM_ERROR</tt>
 if the source
   stream state was inconsistent or if a parameter was invalid, <tt>Z_BUF_ERROR</tt>
   if <tt>strm-&gt;avail_out</tt> was zero.
</p><pre><b>
ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
                                    int good_length,
                                    int max_lazy,
                                    int nice_length,
                                    int max_chain));
</b></pre>
   Fine tune <tt>deflate</tt>'s internal compression parameters.  This 
should only be
   used by someone who understands the algorithm used by <em>zlib</em>'s
 <tt>deflate</tt> for
   searching for the best matching string, and even then only by the 
most
   fanatic optimizer trying to squeeze out the last compressed bit for 
their
   specific input data.  Read the deflate.c source code for the meaning 
of the
   <tt>max_lazy</tt>, <tt>good_length</tt>, <tt>nice_length</tt>, and <tt>max_chain</tt>
 parameters.
<p>
     <tt>deflateTune()</tt> can be called after <tt>deflateInit()</tt> 
or <tt>deflateInit2()</tt>, and
   returns <tt>Z_OK</tt> on success, or <tt>Z_STREAM_ERROR</tt> for an 
invalid deflate stream.
 </p><pre><b>
ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
                                       uLong sourceLen));
</b></pre>
     <tt>deflateBound()</tt> returns an upper bound on the compressed 
size after
   deflation of <tt><tt>sourceLen</tt></tt> bytes.  It must be called 
after <tt>deflateInit()</tt>
   or <tt>deflateInit2()</tt>.  This would be used to allocate an output
 buffer
   for deflation in a single pass, and so would be called before <tt>deflate()</tt>.
<pre><b>
ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
                                     int bits,
                                     int value));
</b></pre>
     <tt>deflatePrime()</tt> inserts bits in the deflate output stream. 
 The intent
  is that this function is used to start off the deflate output with the
  bits leftover from a previous deflate stream when appending to it.  As
 such,
  this function can only be used for raw deflate, and must be used 
before the
  first <tt>deflate()</tt> call after a <tt>deflateInit2()</tt> or <tt>deflateReset()</tt>.
  <tt>bits</tt> must be
  less than or equal to 16, and that many of the least significant bits 
of
  <tt>value</tt> will be inserted in the output.
<p>
      <tt>deflatePrime</tt> returns <tt>Z_OK</tt> if success, or <tt>Z_STREAM_ERROR</tt>
 if the source
   stream state was inconsistent.
</p><pre><b>
ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
                                         gz_headerp head));
</b></pre>
      <tt>deflateSetHeader()</tt> provides <em>gzip</em> header 
information for when a <em>gzip</em>
   stream is requested by <tt>deflateInit2()</tt>.  <tt>deflateSetHeader()</tt>
 may be called
   after <tt>deflateInit2()</tt> or <tt>deflateReset()</tt> and before 
the first call of
   <tt>deflate()</tt>.  The text, time, os, extra field, name, and 
comment information
   in the provided gz_header structure are written to the <em>gzip</em> 
header (xflag is
   ignored &#8212; the extra flags are set according to the compression 
level).  The
   caller must assure that, if not <tt>Z_NULL</tt>, name and comment are
 terminated with
   a zero byte, and that if extra is not <tt>Z_NULL</tt>, that extra_len
 bytes are
   available there.  If hcrc is true, a <em>gzip</em> header crc is 
included.  Note that
   the current versions of the command-line version of <em>gzip</em> (up
 through version
   1.3.x) do not support header crc's, and will report that it is a 
"multi-part
   <em>gzip</em> file" and give up.
<p>
      If <tt>deflateSetHeader</tt> is not used, the default <em>gzip</em>
 header has text false,
   the time set to zero, and os set to 255, with no extra, name, or 
comment
   fields.  The <em>gzip</em> header is returned to the default state by
 <tt>deflateReset()</tt>.
</p><p>
      <tt>deflateSetHeader</tt> returns <tt>Z_OK</tt> if success, or <tt>Z_STREAM_ERROR</tt>
 if the source
   stream state was inconsistent.
</p><pre><b>
ZEXTERN int ZEXPORT inflateInit2 OF((z_streamp strm,
                                     int  windowBits));
</b></pre>
     This is another version of <tt>inflateInit</tt> with an extra 
parameter. The
   fields <tt>next_in</tt>, <tt>avail_in</tt>, <tt>zalloc</tt>, <tt>zfree</tt>
 and <tt>opaque</tt> must be initialized
   before by the caller.
<p>
     The <tt>windowBits</tt> parameter is the base two logarithm of the 
maximum window
   size (the size of the history buffer).  It should be in the range 
8..15 for
   this version of the library. The default value is 15 if <tt>inflateInit</tt>
 is used
   instead. <tt>windowBits</tt> must be greater than or equal to the <tt>windowBits</tt>
 value
   provided to <tt>deflateInit2()</tt> while compressing, or it must be 
equal to 15 if
   <tt>deflateInit2()</tt> was not used. If a compressed stream with a 
larger window
   size is given as input, <tt>inflate()</tt> will return with the error
 code
   <tt>Z_DATA_ERROR</tt> instead of trying to allocate a larger window.
</p><p>
     <tt>windowBits</tt> can also be zero to request that <tt>inflate</tt>
 use the window size in
   the zlib header of the compressed stream.
</p><p>
     <tt>windowBits</tt> can also be &#8211;8..&#8211;15 for raw inflate. In this 
case, <tt>-windowBits</tt>
   determines the window size. <tt>inflate()</tt> will then process raw 
deflate data,
   not looking for a <em>zlib</em> or <em>gzip</em> header, not 
generating a check value, and not
   looking for any check values for comparison at the end of the stream.
 This
   is for use with other formats that use the deflate compressed data 
format
   such as <em>zip</em>.  Those formats provide their own check values. 
If a custom
   format is developed using the raw deflate format for compressed data,
 it is
   recommended that a check value such as an adler32 or a crc32 be 
applied to
   the uncompressed data as is done in the <em>zlib</em>, <em>gzip</em>,
 and <em>zip</em> formats.  For
   most applications, the <em>zlib</em> format should be used as is. 
Note that comments
   above on the use in <tt>deflateInit2()</tt> applies to the magnitude 
of <tt>windowBits</tt>.
</p><p>
     <tt>windowBits</tt> can also be greater than 15 for optional <em>gzip</em>
 decoding. Add
   32 to <tt>windowBits</tt> to enable <em>zlib</em> and <em>gzip</em> 
decoding with automatic header
   detection, or add 16 to decode only the <em>gzip</em> format (the <em>zlib</em>
 format will
   return a <tt>Z_DATA_ERROR</tt>).  If a <em>gzip</em> stream is being 
decoded, <tt>strm-&gt;adler</tt> is
   a crc32 instead of an adler32.
</p><p>
     <tt>inflateInit2</tt> returns <tt>Z_OK</tt> if success, <tt>Z_MEM_ERROR</tt>
 if there was not enough
   memory, <tt>Z_VERSION_ERROR</tt> if the zlib library version is 
incompatible with the
   version assumed by the caller, <tt>Z_STREAM_ERROR</tt> if a 
parameters are invalid, such as a null pointer to the structure. <tt>msg</tt>
   is set to null if there is no error message.  <tt>inflateInit2</tt> 
does not perform
   any decompression apart from reading the <em>zlib</em> header if 
present: actual decompression
   be done by <tt>inflate()</tt>. (So <tt>next_in</tt> and <tt>avail_in</tt>
 may be modified, but <tt>next_out</tt>
   and <tt>avail_out</tt> are unused and unchanged.) The current 
implementation
   of <tt>inflateInit2()</tt> does not process any header information --
 that is
   deferred until <tt>inflate()</tt> is called.
</p><pre><b>
ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
                                             const Bytef *dictionary,
                                             uInt  dictLength));
</b></pre>
     Initializes the decompression dictionary from the given 
uncompressed byte
   sequence. This function must be called immediately after a call of <tt>inflate</tt>,
   if that call returned <tt>Z_NEED_DICT</tt>. The dictionary chosen by 
the compressor
   can be determined from the adler32 value returned by that call of <tt>inflate</tt>.
   The compressor and decompressor must use exactly the same dictionary 
(see
   <tt>deflateSetDictionary</tt>).  For raw inflate, this function can 
be called
   immediately after <tt>inflateInit2()</tt> or <tt>inflateReset()</tt> 
and before any call of
   <tt>inflate()</tt> to set the dictionary.  The application must 
insure that the
   dictionary that was used for compression is provided.
<p>
     <tt>inflateSetDictionary</tt> returns <tt>Z_OK</tt> if success, <tt>Z_STREAM_ERROR</tt>
 if a
   parameter is invalid (such as <tt>NULL</tt> dictionary) or the stream
 state is
   inconsistent, <tt>Z_DATA_ERROR</tt> if the given dictionary doesn't 
match the
   expected one (incorrect adler32 value). <tt>inflateSetDictionary</tt>
 does not
   perform any decompression: this will be done by subsequent calls of
   <tt>inflate()</tt>.
</p><pre><b>
ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
</b></pre>    Skips invalid compressed data until a full flush point 
(see above the
  description of <tt>deflate</tt> with <tt>Z_FULL_FLUSH</tt>) can be 
found, or until all
  available input is skipped. No output is provided.
<p>
    <tt>inflateSync</tt> returns <tt>Z_OK</tt> if a full flush point has
 been found, <tt>Z_BUF_ERROR</tt>
  if no more input was provided, <tt>Z_DATA_ERROR</tt> if no flush point
 has been found,
  or <tt>Z_STREAM_ERROR</tt> if the stream structure was inconsistent. 
In the success
  case, the application may save the current current value of <tt>total_in</tt>
 which
  indicates where valid compressed data was found. In the error case, 
the
  application may repeatedly call <tt>inflateSync</tt>, providing more 
input each time,
  until success or end of the input data.
</p><pre><b>
ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
                                    z_streamp source));
</b></pre>
     Sets the destination stream as a complete copy of the source 
stream.
<p>
     This function can be useful when randomly accessing a large stream.
  The
   first pass through the stream can periodically record the <tt>inflate</tt>
 state,
   allowing restarting <tt>inflate</tt> at those points when randomly 
accessing the
   stream.
</p><p>
     <tt>inflateCopy</tt> returns <tt>Z_OK</tt> if success, <tt>Z_MEM_ERROR</tt>
 if there was not
   enough memory, <tt>Z_STREAM_ERROR</tt> if the source stream state was
 inconsistent
   (such as <tt>zalloc</tt> being <tt>NULL</tt>). <tt>msg</tt> is left 
unchanged in both source and
   destination.
</p><pre><b>
ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
</b></pre>
     This function is equivalent to <tt>inflateEnd</tt> followed by <tt>inflateInit</tt>,
   but does not free and reallocate all the internal decompression 
state.
   The stream will keep attributes that may have been set by <tt>inflateInit2</tt>.
<p>
      <tt>inflateReset</tt> returns <tt>Z_OK</tt> if success, or <tt>Z_STREAM_ERROR</tt>
 if the source
   stream state was inconsistent (such as <tt>zalloc</tt> or state being
 <tt>NULL</tt>).
</p><pre><b>
ZEXTERN int ZEXPORT inflateReset2 OF((z_streamp strm,
                                      int windowBits));
</b></pre>
     This function is the same as <tt>inflateReset</tt>, but it also 
permits changing
   the wrap and window size requests.  The <tt>windowBits</tt> parameter
 is interpreted
   the same as it is for <tt>inflateInit2</tt>.
<p>
     <tt>inflateReset2</tt> returns <tt>Z_OK</tt> if success, or <tt>Z_STREAM_ERROR</tt>
 if the source
   stream state was inconsistent (such as <tt>zalloc</tt> or <tt>state</tt>
 being <tt>Z_NULL</tt>), or if
   the <tt>windowBits parameter</tt> is invalid.
</p><pre><b>
ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
                                     int bits,
                                     int value));
</b></pre>
  This function inserts bits in the <tt>inflate</tt> input stream.  The 
intent is
  that this function is used to start inflating at a bit position in the
  middle of a byte.  The provided bits will be used before any bytes are
 used
  from <tt>next_in</tt>.  This function should only be used with raw 
inflate, and
  should be used before the first <tt>inflate()</tt> call after <tt>inflateInit2()</tt>
 or
  <tt>inflateReset()</tt>.  <tt>bits</tt> must be less than or equal to 
16, and that many of the
  least significant bits of <tt>value</tt> will be inserted in the 
input.
<p>
     If <tt>bits</tt> is negative, then the input stream bit buffer is 
emptied.  Then
   <tt>inflatePrime()</tt> can be called again to put bits in the 
buffer.  This is used
   to clear out bits leftover after feeding inflate a block description 
prior
   to feeding inflate codes.
</p><p>
      <tt>inflatePrime</tt> returns <tt>Z_OK</tt> if success, or <tt>Z_STREAM_ERROR</tt>
 if the source
   stream state was inconsistent.
</p><pre><b>
ZEXTERN long ZEXPORT inflateMark OF((z_streamp strm));
</b></pre>
     This function returns two values, one in the lower 16 bits of the 
return
   value, and the other in the remaining upper bits, obtained by 
shifting the
   return value down 16 bits.  If the upper value is &#8211;1 and the lower 
value is
   zero, then <tt>inflate()</tt> is currently decoding information 
outside of a block.
   If the upper value is &#8211;1 and the lower value is non-zero, then 
inflate is in
   the middle of a stored block, with the lower value equaling the 
number of
   bytes from the input remaining to copy.  If the upper value is not 
&#8211;1, then
   it is the number of bits back from the current bit position in the 
input of
   the code (literal or length/distance pair) currently being processed.
  In
   that case the lower value is the number of bytes already emitted for 
that
   code.
<p>
     A code is being processed if <tt>inflate</tt> is waiting for more 
input to complete
   decoding of the code, or if it has completed decoding but is waiting 
for
   more output space to write the literal or match data.
</p><p>
     <tt>inflateMark()</tt> is used to mark locations in the input data 
for random
   access, which may be at bit positions, and to note those cases where 
the
   output of a code may span boundaries of random access blocks.  The 
current
   location in the input stream can be determined from <tt>avail_in</tt>
 and <tt>data_type</tt>
   as noted in the description for the <tt>Z_BLOCK</tt> flush parameter 
for <tt>inflate</tt>.
</p><p>
     <tt>inflateMark</tt> returns the value noted above or <tt>-1 
&lt;&lt; 16</tt> if the provided
   source stream state was inconsistent.
</p><pre><b>
ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
                                         gz_headerp head));
</b></pre>
   <tt>inflateGetHeader()</tt> requests that <em>gzip</em> header 
information be stored in the
   provided gz_header structure.  <tt>inflateGetHeader()</tt> may be 
called after
   <tt>inflateInit2()</tt> or <tt>inflateReset()</tt>, and before the 
first call of <tt>inflate()</tt>.
   As <tt>inflate()</tt> processes the <em>gzip</em> stream, <tt>head-&gt;done</tt>
 is zero until the header
   is completed, at which time <tt>head-&gt;done</tt> is set to one.  If
 a <em>zlib</em> stream is
   being decoded, then <tt>head-&gt;done</tt> is set to &#8211;1 to indicate 
that there will be
   no <em>gzip</em> header information forthcoming.  Note that <tt>Z_BLOCK</tt>
 can be used to
   force <tt>inflate()</tt> to return immediately after header 
processing is complete
   and before any actual data is decompressed.
<p>
      The text, time, xflags, and os fields are filled in with the <em>gzip</em>
 header
   contents.  hcrc is set to true if there is a header CRC.  (The header
 CRC
   was valid if done is set to one.)  If extra is not <tt>Z_NULL</tt>, 
then extra_max
   contains the maximum number of bytes to write to extra.  Once done is
 true,
   extra_len contains the actual extra field length, and extra contains 
the
   extra field, or that field truncated if extra_max is less than 
extra_len.
   If name is not <tt>Z_NULL</tt>, then up to name_max characters are 
written there,
   terminated with a zero unless the length is greater than name_max.  
If
   comment is not <tt>Z_NULL</tt>, then up to comm_max characters are 
written there,
   terminated with a zero unless the length is greater than comm_max.  
When
   any of extra, name, or comment are not <tt>Z_NULL</tt> and the 
respective field is
   not present in the header, then that field is set to <tt>Z_NULL</tt> 
to signal its
   absence.  This allows the use of <tt>deflateSetHeader()</tt> with the
 returned
   structure to duplicate the header.  However if those fields are set 
to
   allocated memory, then the application will need to save those 
pointers
   elsewhere so that they can be eventually freed.
</p><p>
      If <tt>inflateGetHeader</tt> is not used, then the header 
information is simply
   discarded.  The header is always checked for validity, including the 
header
   CRC if present.  <tt>inflateReset()</tt> will reset the process to 
discard the header
   information.  The application would need to call <tt>inflateGetHeader()</tt>
 again to
   retrieve the header from the next <em>gzip</em> stream.
</p><p>
      <tt>inflateGetHeader</tt> returns <tt>Z_OK</tt> if success, or <tt>Z_STREAM_ERROR</tt>
 if the source
   stream state was inconsistent.
</p><pre><b>
ZEXTERN int ZEXPORT inflateBackInit OF((z_streamp strm, int windowBits,
                                        unsigned char FAR *window));
</b></pre>
     Initialize the internal stream state for decompression using <tt>inflateBack()</tt>
   calls.  The fields <tt>zalloc</tt>, <tt>zfree</tt> and <tt>opaque</tt>
 in strm must be initialized
   before the call.  If <tt>zalloc</tt> and <tt>zfree</tt> are <tt>Z_NULL</tt>,
 then the default library-
   derived memory allocation routines are used.  <tt>windowBits</tt> is 
the base two
   logarithm of the window size, in the range 8..15.  window is a caller
   supplied buffer of that size.  Except for special applications where 
it is
   assured that <tt>deflate</tt> was used with small window sizes, <tt>windowBits</tt>
 must be 15
   and a 32K byte window must be supplied to be able to decompress 
general
   deflate streams.
<p>
     See <tt>inflateBack()</tt> for the usage of these routines.
</p><p>
     <tt>inflateBackInit</tt> will return <tt>Z_OK</tt> on success, <tt>Z_STREAM_ERROR</tt>
 if any of
   the paramaters are invalid, <tt>Z_MEM_ERROR</tt> if the internal 
state could not
   be allocated, or <tt>Z_VERSION_ERROR</tt> if the version of the 
library does not
   match the version of the header file.
</p><pre><b>
typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));

ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
                                    in_func in, void FAR *in_desc,
                                    out_func out, void FAR *out_desc));
</b></pre>
     <tt>inflateBack()</tt> does a raw inflate with a single call using a
 call-back
   interface for input and output.  This is more efficient than <tt>inflate()</tt>
 for
   file i/o applications in that it avoids copying between the output 
and the
   sliding window by simply making the window itself the output buffer. 
 This
   function trusts the application to not change the output buffer 
passed by
   the output function, at least until <tt>inflateBack()</tt> returns.
<p>
     <tt>inflateBackInit()</tt> must be called first to allocate the 
internal state
   and to initialize the state with the user-provided window buffer.
   <tt>inflateBack()</tt> may then be used multiple times to <tt>inflate</tt>
 a complete, raw
   deflate stream with each call.  <tt>inflateBackEnd()</tt> is then 
called to free
   the allocated state.
</p><p>
     A raw deflate stream is one with no <em>zlib</em> or <em>gzip</em> 
header or trailer.
   This routine would normally be used in a utility that reads <em>zip</em>
 or <em>gzip</em>
   files and writes out uncompressed files.  The utility would decode 
the
   header and process the trailer on its own, hence this routine expects
   only the raw deflate stream to decompress.  This is different from 
the
   normal behavior of <tt>inflate()</tt>, which expects either a <em>zlib</em>
 or <em>gzip</em> header and
   trailer around the deflate stream.
</p><p>
     <tt>inflateBack()</tt> uses two subroutines supplied by the caller 
that are then
   called by <tt>inflateBack()</tt> for input and output.  <tt>inflateBack()</tt>
 calls those
   routines until it reads a complete deflate stream and writes out all 
of the
   uncompressed data, or until it encounters an error.  The function's
   parameters and return types are defined above in the <tt>in_func</tt>
 and <tt>out_func</tt>
   typedefs.  <tt>inflateBack()</tt> will call <tt>in(in_desc, &amp;buf)</tt>
 which should return the
   number of bytes of provided input, and a pointer to that input in 
buf.  If
   there is no input available, <tt>in()</tt> must return zero&#8212;<tt>buf</tt>
 is ignored in that
   case&#8212;and <tt>inflateBack()</tt> will return a buffer error.  <tt>inflateBack()</tt>
 will call
   <tt>out(out_desc, buf, len)</tt> to write the uncompressed data <tt>buf[0..len-1]</tt>.
  <tt>out()</tt>
   should return zero on success, or non-zero on failure.  If <tt>out()</tt>
 returns
   non-zero, <tt>inflateBack()</tt> will return with an error.  Neither <tt>in()</tt>
 nor <tt>out()</tt>
   are permitted to change the contents of the window provided to
   <tt>inflateBackInit()</tt>, which is also the buffer that <tt>out()</tt>
 uses to write from.
   The length written by <tt>out()</tt> will be at most the window size.
  Any non-zero
   amount of input may be provided by <tt>in()</tt>.
</p><p>
     For convenience, <tt>inflateBack()</tt> can be provided input on 
the first call by
   setting <tt>strm-&gt;next_in</tt> and <tt>strm-&gt;avail_in</tt>.  If
 that input is exhausted, then
   <tt>in()</tt> will be called.  Therefore <tt>strm-&gt;next_in</tt> 
must be initialized before
   calling <tt>inflateBack()</tt>.  If <tt>strm-&gt;next_in</tt> is <tt>Z_NULL</tt>,
 then <tt>in()</tt> will be called
   immediately for input.  If <tt>strm-&gt;next_in</tt> is not <tt>Z_NULL</tt>,
 then <tt>strm-&gt;avail_in</tt>
   must also be initialized, and then if <tt>strm-&gt;avail_in</tt> is 
not zero, input will
   initially be taken from <tt>strm-&gt;next_in[0 .. strm-&gt;avail_in -
 1]</tt>.
</p><p>
     The <tt>in_desc</tt> and <tt>out_desc</tt> parameters of <tt>inflateBack()</tt>
 is passed as the
   first parameter of <tt>in()</tt> and <tt>out()</tt> respectively when
 they are called.  These
   descriptors can be optionally used to pass any information that the 
caller-
   supplied <tt>in()</tt> and <tt>out()</tt> functions need to do their 
job.
</p><p>
     On return, <tt>inflateBack()</tt> will set <tt>strm-&gt;next_in</tt>
 and <tt>strm-&gt;avail_in</tt> to
   pass back any unused input that was provided by the last <tt>in()</tt>
 call.  The
   return values of <tt>inflateBack()</tt> can be <tt>Z_STREAM_END</tt> 
on success, <tt>Z_BUF_ERROR</tt>
   if <tt>in()</tt> or <tt>out()</tt> returned an error, <tt>Z_DATA_ERROR</tt>
 if there was a format
   error in the deflate stream (in which case <tt>strm-&gt;msg</tt> is 
set to indicate the
   nature of the error), or <tt>Z_STREAM_ERROR</tt> if the stream was 
not properly
   initialized.  In the case of <tt>Z_BUF_ERROR</tt>, an input or output
 error can be
   distinguished using <tt>strm-&gt;next_in</tt> which will be <tt>Z_NULL</tt>
 only if <tt>in()</tt> returned
   an error.  If <tt>strm-&gt;next_in</tt> is not <tt>Z_NULL</tt>, then 
the <tt>Z_BUF_ERROR</tt> was due to
   <tt>out()</tt> returning non-zero.  (<tt>in()</tt> will always be 
called before <tt>out()</tt>, so
   <tt>strm-&gt;next_in</tt> is assured to be defined if <tt>out()</tt> 
returns non-zero.)  Note
   that <tt>inflateBack()</tt> cannot return <tt>Z_OK</tt>.
</p><pre><b>
ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
</b></pre>
     All memory allocated by <tt>inflateBackInit()</tt> is freed.
<p>
     <tt>inflateBackEnd()</tt> returns <tt>Z_OK</tt> on success, or <tt>Z_STREAM_ERROR</tt>
 if the stream
   state was inconsistent.
</p><pre><b>
ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
</b></pre>
Return flags indicating compile-time options.
<p>
    Type sizes, two bits each, 00 = 16 bits, 01 = 32, 10 = 64, 11 = 
other:
</p><ul>
<li> 1.0: size of <tt>uInt</tt>
</li><li> 3.2: size of <tt>uLong</tt>
</li><li> 5.4: size of <tt>voidpf</tt> (pointer)
</li><li> 7.6: size of <tt>z_off_t</tt>
</li></ul>
    Compiler, assembler, and debug options:
<ul>
<li> 8: <tt>DEBUG</tt>
</li><li> 9: <tt>ASMV</tt> or <tt>ASMINF</tt> &#8212; use ASM code
</li><li> 10: <tt>ZLIB_WINAPI</tt> &#8212; exported functions use the WINAPI 
calling convention
</li><li> 11: 0 (reserved)
</li></ul>
    One-time table building (smaller code, but not thread-safe if true):
<ul>
<li> 12: <tt>BUILDFIXED</tt> &#8212; build static block decoding tables when 
needed
</li><li> 13: <tt>DYNAMIC_CRC_TABLE</tt> &#8212; build CRC calculation tables 
when needed
</li><li> 14,15: 0 (reserved)
</li></ul>
    Library content (indicates missing functionality):
<ul>
<li> 16: <tt>NO_GZCOMPRESS</tt> &#8212; <tt>gz</tt>* functions cannot compress
 (to avoid linking
                     deflate code when not needed)
</li><li> 17: <tt>NO_GZIP</tt> &#8212; <tt>deflate</tt> can't write <em>gzip</em>
 streams, and <tt>inflate</tt> can't detect
               and decode <em>gzip</em> streams (to avoid linking crc 
code)
</li><li> 18-19: 0 (reserved)
</li></ul>
    Operation variations (changes in library functionality):
<ul>
<li> 20: <tt>PKZIP_BUG_WORKAROUND</tt> &#8212; slightly more permissive <tt>inflate</tt>
</li><li> 21: <tt>FASTEST</tt> &#8212; <tt>deflate</tt> algorithm with only 
one, lowest compression level
</li><li> 22,23: 0 (reserved)
</li></ul>
    The <tt>sprintf</tt> variant used by <tt>gzprintf</tt> (zero is 
best):
<ul>
<li> 24: 0 = <tt>vs</tt>*, 1 = <tt>s</tt>* &#8212; 1 means limited to 20 
arguments after the format
</li><li> 25: 0 = *<tt>nprintf</tt>, 1 = *<tt>printf</tt> &#8212; 1 means <tt>gzprintf()</tt>
 not secure!
</li><li> 26: 0 = returns value, 1 = <tt>void</tt> &#8212; 1 means inferred 
string length returned
</li></ul>
    Remainder:
<ul>
<li> 27-31: 0 (reserved)
</li></ul>
<a name="Utility"></a><h2> Utility Functions </h2>
     The following utility functions are implemented on top of the
   basic stream-oriented functions. To simplify the interface, some
   default options are assumed (compression level and memory usage,
   standard memory allocation functions). The source code of these
   utility functions can easily be modified if you need special options.
<pre><b>
ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
                                 const Bytef *source, uLong sourceLen));
</b></pre>
     Compresses the source buffer into the destination buffer.  <tt>sourceLen</tt>
 is
   the byte length of the source buffer. Upon entry, <tt>destLen</tt> is
 the total
   size of the destination buffer, which must be at least the value 
returned
   by <tt>compressBound(sourceLen)</tt>. Upon exit, <tt>destLen</tt> is 
the actual size of the
   compressed buffer.
<p>
     compress returns <tt>Z_OK</tt> if success, <tt>Z_MEM_ERROR</tt> if 
there was not
   enough memory, <tt>Z_BUF_ERROR</tt> if there was not enough room in 
the output
   buffer.
</p><pre><b>
ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
                                  const Bytef *source, uLong sourceLen,
                                  int level));
</b></pre>
     Compresses the source buffer into the destination buffer. The <tt>level</tt>
   parameter has the same meaning as in <tt>deflateInit</tt>.  <tt>sourceLen</tt>
 is the byte
   length of the source buffer. Upon entry, <tt>destLen</tt> is the 
total size of the
   destination buffer, which must be at least the value returned by
   <tt>compressBound(sourceLen)</tt>. Upon exit, <tt>destLen</tt> is the
 actual size of the
   compressed buffer.
<p>
     <tt>compress2</tt> returns <tt>Z_OK</tt> if success, <tt>Z_MEM_ERROR</tt>
 if there was not enough
   memory, <tt>Z_BUF_ERROR</tt> if there was not enough room in the 
output buffer,
   <tt>Z_STREAM_ERROR</tt> if the <tt>level</tt> parameter is invalid.
</p><pre><b>
ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
</b></pre>
     <tt>compressBound()</tt> returns an upper bound on the compressed 
size after
   <tt>compress()</tt> or <tt>compress2()</tt> on <tt>sourceLen</tt> 
bytes.  It would be used before
   a <tt>compress()</tt> or <tt>compress2()</tt> call to allocate the 
destination buffer.
<pre><b>
ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
                                   const Bytef *source, uLong sourceLen));
</b></pre>
     Decompresses the source buffer into the destination buffer.  <tt>sourceLen</tt>
 is
   the byte length of the source buffer. Upon entry, <tt>destLen</tt> is
 the total
   size of the destination buffer, which must be large enough to hold 
the
   entire uncompressed data. (The size of the uncompressed data must 
have
   been saved previously by the compressor and transmitted to the 
decompressor
   by some mechanism outside the scope of this compression library.)
   Upon exit, <tt>destLen</tt> is the actual size of the compressed 
buffer.
<p>
     <tt>uncompress</tt> returns <tt>Z_OK</tt> if success, <tt>Z_MEM_ERROR</tt>
 if there was not
   enough memory, <tt>Z_BUF_ERROR</tt> if there was not enough room in 
the output
   buffer, or <tt>Z_DATA_ERROR</tt> if the input data was corrupted or 
incomplete.
<a name="Gzip"></a></p><h2> gzip File Access Functions </h2>
     This library supports reading and writing files in <em>gzip</em> 
(.gz) format with
   an interface similar to that of stdio, using the functions that start
 with
   "<tt>gz</tt>".  The <em>gzip</em> format is different from the <em>zlib</em>
 format.  <em>gzip</em> is a gzip
   wrapper, documented in RFC 1952, wrapped around a deflate stream.
<pre><b>typedef voidp gzFile;       /* opaque gzip file descriptor */

ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
</b></pre>
     Opens a <em>gzip</em> (.gz) file for reading or writing. The <tt>mode</tt>
 parameter
   is as in <tt>fopen</tt> (<tt>"rb"</tt> or <tt>"wb"</tt>) but can also
 include a compression level
   (<tt>"wb9"</tt>) or a strategy: <tt>'f'</tt> for filtered data as in <tt>"wb6f"</tt>,
 <tt>'h'</tt> for
   Huffman-only compression as in <tt>"wb1h"</tt>, <tt>'R'</tt> for 
run-length encoding
   as in <tt>"wb1R"</tt>, or 'F'
   for fixed code compression as in "wb9F". (See the description of <tt>deflateInit2</tt>
 for more information
   about the <tt>strategy</tt> parameter.) Also "a"
   can be used instead of "w" to request that the <em>gzip</em> stream 
that will be
   written be appended to the file.  "+" will result in an error, since 
reading
   and writing to the same gzip file is not supported.
<p>
     <tt>gzopen</tt> can be used to read a file which is not in <em>gzip</em>
 format; in this
   case <tt>gzread</tt> will directly read from the file without 
decompression.
</p><p>
     <tt>gzopen</tt> returns <tt>NULL</tt> if the file could not be 
opened, if there was
   insufficient memory to allocate the <tt>gzFile</tt> state, or if an 
invalid mode was
   specified (an 'r', 'w', or 'a' was not provided, or '+' was 
provided). <tt>errno</tt>
   can be checked to determine if the reason <tt>gzopen</tt> failed was 
that the
   file could not be opened.
</p><pre><b>
ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
</b></pre>
     <tt>gzdopen()</tt> associates a <tt>gzFile</tt> with the file 
descriptor <tt>fd</tt>.  File
   descriptors are obtained from calls like <tt>open</tt>, <tt>dup</tt>,
 <tt>creat</tt>, <tt>pipe</tt> or
   <tt>fileno</tt> (in the file has been previously opened with <tt>fopen</tt>).

   The mode parameter is as in <tt>gzopen</tt>.
     The next call of <tt>gzclose</tt> on the returned <tt>gzFile</tt> 
will also close the
   file descriptor <tt>fd</tt>, just like <tt>fclose(fdopen(fd), mode)</tt>
 closes the file
   descriptor <tt>fd</tt>. If you want to keep <tt>fd</tt> open, use <tt>fd
 = dup(fd_keep); gz = gzdopen(fd,
   mode);</tt>.  The duplicated descriptor should be saved to avoid a 
leak, since
   <tt>gzdopen</tt> does not close <tt>fd</tt> if it fails.
<p>
     <tt>gzdopen</tt> returns <tt>NULL</tt> if there was insufficient 
memory to allocate
   the <tt>gzFile</tt> state, if an invalid <tt>mode</tt> was specified 
(an 'r', 'w', or 'a' was not
   provided, or '+' was provided), or if <tt>fd</tt> is &#8211;1.  The file 
descriptor is not
   used until the next <tt>gz</tt>* read, write, seek, or close 
operation, so <tt>gzdopen</tt>
   will not detect if <tt>fd</tt> is invalid (unless <tt>fd</tt> is &#8211;1).
</p><pre><b>
ZEXTERN int ZEXPORT gzbuffer OF((gzFile file, unsigned size));
</b></pre>
     Set the internal buffer size used by this library's functions.  The
   default buffer size is 8192 bytes.  This function must be called 
after
   <tt>gzopen()</tt> or <tt>gzdopen()</tt>, and before any other calls 
that read or write the
   file.  The buffer memory allocation is always deferred to the first 
read or
   write.  Two buffers are allocated, either both of the specified size 
when
   writing, or one of the specified size and the other twice that size 
when
   reading.  A larger buffer size of, for example, 64K or 128K bytes 
will
   noticeably increase the speed of decompression (reading).
<p>
     The new buffer size also affects the maximum length for <tt>gzprintf()</tt>.
</p><p>
     <tt>gzbuffer()</tt> returns 0 on success, or &#8211;1 on failure, such as
 being called
   too late.
</p><pre><b>
ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
</b></pre>
     Dynamically update the compression <tt>level</tt> or <tt>strategy</tt>.
 See the description
   of <tt>deflateInit2</tt> for the meaning of these parameters.
<p>
     <tt>gzsetparams</tt> returns <tt>Z_OK</tt> if success, or <tt>Z_STREAM_ERROR</tt>
 if the file was not
   opened for writing.
</p><pre><b>
ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
</b></pre>
     Reads the given number of uncompressed bytes from the compressed 
file.
   If the input file was not in <em>gzip</em> format, <tt>gzread</tt> 
copies the given number
   of bytes into the buffer.
<p>
     After reaching the end of a <em>gzip</em> stream in the input, <tt>gzread</tt>
 will continue
   to read, looking for another <em>gzip</em> stream, or failing that, 
reading the rest
   of the input file directly without decompression.  The entire input 
file
   will be read if <tt>gzread</tt> is called until it returns less than 
the requested
   <tt>len</tt>.
</p><p>
     <tt>gzread</tt> returns the number of uncompressed bytes actually 
read (0 for
   end of file, &#8211;1 for error). </p><pre><b>
ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
                                voidpc buf, unsigned len));
</b></pre>
     Writes the given number of uncompressed bytes into the compressed 
file.
   <tt>gzwrite</tt> returns the number of uncompressed bytes actually 
written
   or 0 in case of error.
<pre><b>
ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
</b></pre>
     Converts, formats, and writes the arguments to the compressed file 
under
   control of the <tt>format</tt> string, as in <tt>fprintf</tt>. <tt>gzprintf</tt>
 returns the number of
   uncompressed bytes actually written, or 0 in case of error.  The 
number of
   uncompressed bytes written is limited to 8191, or one less than the 
buffer
   size given to <tt>gzbuffer()</tt>. The caller should assure that
   this limit is not exceeded. If it is exceeded, then <tt>gzprintf()</tt>
 will return
   return an error (0) with nothing written. In this case, there may 
also be a
   buffer overflow with unpredictable consequences, which is possible 
only if
   <em>zlib</em> was compiled with the insecure functions <tt>sprintf()</tt>
 or <tt>vsprintf()</tt>
   because the secure <tt>snprintf()</tt> or <tt>vsnprintf()</tt> 
functions were not available.
   This can be determined using <tt>zlibCompileFlags()</tt>.
<pre><b>
ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
</b></pre>
      Writes the given null-terminated string to the compressed file, 
excluding
   the terminating null character.
<p>
      <tt>gzputs</tt> returns the number of characters written, or &#8211;1 in
 case of error.
</p><pre><b>
ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
</b></pre>
      Reads bytes from the compressed file until <tt>len-1</tt> 
characters are read, or
   a newline character is read and transferred to <tt>buf</tt>, or an 
end-of-file
   condition is encountered.  If any characters are read or if <tt>len 
== 1</tt>, the
   string is terminated with a null character.  If no characters are 
read due
   to an end-of-file or <tt>len &lt; 1</tt>, then the buffer is left 
untouched.
<p>
     <tt>gzgets</tt> returns <tt>buf</tt> which is a null-terminated 
string, or it returns <tt>NULL</tt>
   for end-of-file or in case of error.  If there was an error, the 
contents at
   <tt>buf</tt> are indeterminate.
</p><pre><b>
ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
</b></pre>
      Writes <tt>c</tt>, converted to an <tt>unsigned char</tt>, into 
the compressed file.
   <tt>gzputc</tt> returns the value that was written, or &#8211;1 in case of 
error.
<pre><b>
ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
</b></pre>
      Reads one byte from the compressed file. <tt>gzgetc</tt> returns 
this byte
   or &#8211;1 in case of end of file or error.
<pre><b>
ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
</b></pre>
      Push one character back onto the stream to be read as the first 
character
   on the next read.  At least one character of push-back is allowed.
   <tt>gzungetc()</tt> returns the
   character pushed, or &#8211;1 on failure.  <tt>gzungetc()</tt> will
   fail if <tt>c</tt> is &#8211;1, and may fail if a character has been pushed
 but not read
   yet. If <tt>gzungetc</tt> is used immediately after <tt>gzopen</tt> 
or <tt>gzdopen</tt>, at least the
   output buffer size of pushed characters is allowed.  (See <tt>gzbuffer</tt>
 above.) The pushed
   character will be discarded if the stream is repositioned with <tt>gzseek()</tt>
   or <tt>gzrewind()</tt>.
<pre><b>
ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
</b></pre>
     Flushes all pending output into the compressed file. The parameter
   <tt>flush</tt> is as in the <tt>deflate()</tt> function. The return 
value is the <em>zlib</em>
   error number (see function <tt>gzerror</tt> below). <tt>gzflush</tt> 
is only permitted when writing.
<p>
     If the flush parameter is <tt>Z_FINISH</tt>, the remaining data is 
written and the
   <em>gzip</em> stream is completed in the output.  If <tt>gzwrite()</tt>
 is called again, a new
   <em>gzip</em> stream will be started in the output.  <tt>gzread()</tt>
 is able to read such
   concatented <em>gzip</em> streams.
</p><p>
     <tt>gzflush</tt> should be called only when strictly necessary 
because it will
   degrade compression if called too often.
</p><pre><b>
ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
                                   z_off_t offset, int whence));
</b></pre>
      Sets the starting position for the next <tt>gzread</tt> or <tt>gzwrite</tt>
 on the
   given compressed file. The offset represents a number of bytes in the
   uncompressed data stream. The <tt>whence</tt> parameter is defined as
 in <tt>lseek</tt>(2);
   the value <tt>SEEK_END</tt> is not supported.
<p>
     If the file is opened for reading, this function is emulated but 
can be
   extremely slow. If the file is opened for writing, only forward seeks
 are
   supported; <tt>gzseek</tt> then compresses a sequence of zeroes up to
 the new
   starting position.
</p><p>
      <tt>gzseek</tt> returns the resulting offset location as measured 
in bytes from
   the beginning of the uncompressed stream, or &#8211;1 in case of error, in
   particular if the file is opened for writing and the new starting 
position
   would be before the current position.
</p><pre><b>
ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
</b></pre>
     Rewinds the given file. This function is supported only for 
reading.
<p>
   <tt>gzrewind(file)</tt> is equivalent to <tt>(int)gzseek(file, 0L, 
SEEK_SET)</tt>
</p><pre><b>
ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
</b></pre>
     Returns the starting position for the next <tt>gzread</tt> or <tt>gzwrite</tt>
 on the
   given compressed file. This position represents a number of bytes in 
the
   uncompressed data stream, and is zero when starting, even if 
appending or
   reading a <em>gzip</em> stream from the middle of a file using <tt>gzdopen()</tt>.
<p>
   <tt>gztell(file)</tt> is equivalent to <tt>gzseek(file, 0L, SEEK_CUR)</tt>
</p><pre><b>
ZEXTERN z_off_t ZEXPORT gzoffset OF((gzFile file));
</b></pre>
     Returns the current offset in the file being read or written.  This
 offset
   includes the count of bytes that precede the <em>gzip</em> stream, 
for example when
   appending or when using <em>gzdopen()</em> for reading.  When 
reading, the offset
   does not include as yet unused buffered input.  This information can 
be used
   for a progress indicator.  On error, <em>gzoffset()</em> returns &#8211;1.
<pre><b>
ZEXTERN int ZEXPORT gzeof OF((gzFile file));
</b></pre>
     Returns true (1) if the end-of-file indicator has been set while 
reading,
   false (0) otherwise.  Note that the end-of-file indicator is set only
 if the
   read tried to go past the end of the input, but came up short.  
Therefore,
   just like <tt>feof()</tt>, <tt>gzeof()</tt> may return false even if 
there is no more data to
   read, in the event that the last read request was for the exact 
number of
   bytes remaining in the input file.  This will happen if the input 
file size
   is an exact multiple of the buffer size.
<p>
     If <tt>gzeof()</tt> returns true, then the read functions will 
return no more data,
   unless the end-of-file indicator is reset by <tt>gzclearerr()</tt> 
and the input file
   has grown since the previous end of file was detected.
</p><pre><b>
ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
</b></pre>
     Returns true (1) if file is being copied directly while reading, or
 false
   (0) if file is a <em>gzip</em> stream being decompressed.  This state
 can change from
   false to true while reading the input file if the end of a gzip 
stream is
   reached, but is followed by data that is not another <em>gzip</em> 
stream.
<p>
     If the input file is empty, <tt>gzdirect()</tt> will return true, 
since the input
   does not contain a <em>gzip</em> stream.
</p><p>
     If <tt>gzdirect()</tt> is used immediately after <tt>gzopen()</tt> 
or <tt>gzdopen()</tt> it will
   cause buffers to be allocated to allow reading the file to determine 
if it
   is a <em>gzip</em> file.  Therefore if <tt>gzbuffer()</tt> is used, 
it should be called before
   <tt>gzdirect()</tt>.
</p><pre><b>
ZEXTERN int ZEXPORT gzclose OF((gzFile file));
</b></pre>
     Flushes all pending output if necessary, closes the compressed file
 and
   deallocates the (de)compression state.  Note that once file is 
closed, you
   cannot call <tt>gzerror</tt> with file, since its structures have 
been deallocated.
   <tt>gzclose</tt> must not be called more than once on the same file, 
just as <tt>free</tt>
   must not be called more than once on the same allocation.
<p>
     <tt>gzclose</tt> will return <tt>Z_STREAM_ERROR</tt> if file is not
 valid, <tt>Z_ERRNO</tt> on a
   file operation error, or <tt>Z_OK</tt> on success.
</p><pre><b>
ZEXTERN int ZEXPORT gzclose_r OF((gzFile file));
ZEXTERN int ZEXPORT gzclose_w OF((gzFile file));
</b></pre>
     Same as <tt>gzclose()</tt>, but <tt>gzclose_r()</tt> is only for 
use when reading, and
   <tt>gzclose_w()</tt> is only for use when writing or appending.  The 
advantage to
   using these instead of <tt>gzclose()</tt> is that they avoid linking 
in <em>zlib</em>
   compression or decompression code that is not used when only reading 
or only
   writing respectively.  If <tt>gzclose()</tt> is used, then both 
compression and
   decompression code will be included the application when linking to a
 static
   <em>zlib</em> library.
<pre><b>
ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
</b></pre>
     Returns the error message for the last error which occurred on the
   given compressed <tt>file</tt>. <tt>errnum</tt> is set to <em>zlib</em>
 error number. If an
   error occurred in the file system and not in the compression library,
   <tt>errnum</tt> is set to <tt>Z_ERRNO</tt> and the application may 
consult <tt>errno</tt>
   to get the exact error code.
<p>
     The application must not modify the returned string.  Future calls 
to
   this function may invalidate the previously returned string.  If file
 is
   closed, then the string previously returned by <tt>gzerror</tt> will 
no longer be
   available.
</p><p>
     <tt>gzerror()</tt> should be used to distinguish errors from 
end-of-file for those
   functions above that do not distinguish those cases in their return 
values.
</p><pre><b>
ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
</b></pre>
     Clears the error and end-of-file flags for <tt>file</tt>. This is 
analogous to the
   <tt>clearerr()</tt> function in <tt>stdio</tt>. This is useful for 
continuing to read a <em>gzip</em>
   file that is being written concurrently.
<a name="Checksum"></a><h2> Checksum Functions </h2>
     These functions are not related to compression but are exported
   anyway because they might be useful in applications using the
   compression library.
<pre><b>
ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
</b></pre>
     Update a running Adler-32 checksum with the bytes <tt>buf[0..len-1]</tt>
 and
   return the updated checksum. If <tt>buf</tt> is <tt>NULL</tt>, this 
function returns
   the required initial value for the checksum.
<p>
   An Adler-32 checksum is almost as reliable as a CRC32 but can be 
computed
   much faster.
</p><p>
Usage example:
</p><pre>     uLong adler = adler32(0L, Z_NULL, 0);

     while (read_buffer(buffer, length) != EOF) {
       adler = adler32(adler, buffer, length);
     }
     if (adler != original_adler) error();
</pre>
<pre><b>
ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
                                          z_off_t len2));
</b></pre>
     Combine two Adler-32 checksums into one.  For two sequences of 
bytes, <tt>seq1</tt>
   and <tt>seq2</tt> with lengths <tt>len1</tt> and <tt>len2</tt>, 
Adler-32 checksums were calculated for
   each, <tt>adler1</tt> and <tt>adler2</tt>.  <tt>adler32_combine()</tt>
 returns the Adler-32 checksum of
   <tt>seq1</tt> and <tt>seq2</tt> concatenated, requiring only <tt>adler1</tt>,
 <tt>adler2</tt>, and <tt>len2</tt>.
<pre><b>
ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
</b></pre>
     Update a running CRC-32 with the bytes <tt>buf[0..len-1]</tt> and 
return the
   updated CRC-32. If <tt>buf</tt> is <tt>Z_NULL</tt>, this function 
returns the required initial
   value for the for the crc. Pre- and post-conditioning (one's 
complement) is
   performed within this function so it shouldn't be done by the 
application.
<p>
   Usage example:
</p><pre>     uLong crc = crc32(0L, Z_NULL, 0);

     while (read_buffer(buffer, length) != EOF) {
       crc = crc32(crc, buffer, length);
     }
     if (crc != original_crc) error();
</pre>
<pre><b>
ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
</b></pre>
   Combine two CRC-32 check values into one.  For two sequences of 
bytes,
   <tt>seq1</tt> and <tt>seq2</tt> with lengths <tt>len1</tt> and <tt>len2</tt>,
 CRC-32 check values were
   calculated for each, <tt>crc1</tt> and <tt>crc2</tt>.  <tt>crc32_combine()</tt>
 returns the CRC-32
   check value of <tt>seq1</tt> and <tt>seq2</tt> concatenated, 
requiring only <tt>crc1</tt>, <tt>crc2</tt>, and
   <tt>len2</tt>.
<a name="Undocumented"></a><h2> Undocumented Functions </h2>
<pre><b>ZEXTERN const char   * ZEXPORT zError           OF((int));
ZEXTERN int            ZEXPORT inflateSyncPoint OF((z_streamp z));
ZEXTERN const uLongf * ZEXPORT get_crc_table    OF((void));
ZEXTERN int            ZEXPORT inflateUndermine OF((z_streamp, int));
</b></pre>
</body></html>